// admin/users/detail/detail.js
Page({
  data: {
    userId: '',
    userInfo: null,
    loading: true
  },

  onLoad: function(options) {
    if (options && options.id) {
      this.setData({
        userId: options.id
      });
      this.fetchUserDetail();
    } else {
      wx.showToast({
        title: '用户ID不存在',
        icon: 'none'
      });
      setTimeout(() => {
        wx.navigateBack();
      }, 1500);
    }
  },

  fetchUserDetail: function() {
    // 模拟获取用户详情数据
    setTimeout(() => {
      this.setData({
        userInfo: {
          id: this.data.userId,
          username: '用户' + this.data.userId,
          avatar: '/images/user.png',
          registerDate: '2023-0' + (Math.floor(Math.random() * 9) + 1) + '-' + (Math.floor(Math.random() * 28) + 1),
          lastLoginDate: '2023-1' + (Math.floor(Math.random() * 2) + 0) + '-' + (Math.floor(Math.random() * 28) + 1),
          learningDays: Math.floor(Math.random() * 30) + 1,
          totalWords: Math.floor(Math.random() * 1000) + 100,
          learnedWords: Math.floor(Math.random() * 500) + 50,
          favoriteWords: Math.floor(Math.random() * 100) + 10
        },
        loading: false
      });
    }, 1000);
  },

  // 返回用户列表
  goBack: function() {
    wx.navigateBack();
  }
});